package com.hschinese.pronunciation.widget;

import android.app.Activity;
import android.content.Context;
import android.database.Cursor;
import android.graphics.drawable.AnimationDrawable;
import android.os.Handler;
import android.os.Message;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.AlphaAnimation;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.view.animation.ScaleAnimation;
import android.view.animation.TranslateAnimation;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.hschinese.pronunciation.R;
import com.hschinese.pronunciation.bean.AppDataBean;
import com.hschinese.pronunciation.bean.Type15Bean;
import com.hschinese.pronunciation.db.DBHelper;
import com.hschinese.pronunciation.interfaces.LessonProgressInterface;
import com.hschinese.pronunciation.interfaces.NextLessonInterface;
import com.hschinese.pronunciation.utils.AnimatorUtil;
import com.hschinese.pronunciation.utils.HsSoundUtil;
import com.hschinese.pronunciation.utils.Logger;
import com.hschinese.pronunciation.utils.Utils;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.Timer;
import java.util.TimerTask;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;

import static com.hschinese.pronunciation.R.id.iv_constrution_left;

/**
 * Created by wo on 2015/11/5.
 */
public class StudyConsructionView extends LinearLayout {
    @Bind(R.id.tv_hao)
    TextView tvHao;
    @Bind(R.id.iv_constrution_up_left)
    ImageView ivConstrutionUpLeft;
    @Bind(R.id.iv_constrution_up_right)
    ImageView ivConstrutionUpRight;
    @Bind(R.id.ll_pingfeng)
    LinearLayout llPingfeng;
    @Bind(R.id.iv_xiaoshou_constrution)
    ImageView ivXiaoshouConstrution;
    @Bind(R.id.rl_contstrction_parient)
    RelativeLayout rl_contstrction_parient;
    @Bind(R.id.tv_constrution_up_left)
    TextView tvConstrutionUpLeft;
    @Bind(R.id.tv_constrution_up_right)
    TextView tvConstrutionUpRight;


    @Bind(R.id.rl_constrution_up_left)
    RelativeLayout rlConstrutionUpLeft;
    @Bind(R.id.rl_constrution_up_right)
    RelativeLayout rlConstrutionUpRight;
    @Bind(R.id.tv_constrution_up_up_center1)
    TextView tvConstrutionUpUpCenter1;
    @Bind(R.id.rl_constrution_up_center1)
    RelativeLayout rlConstrutionUpCenter1;
    @Bind(R.id.tv_constrution_up_up_center2)
    TextView tvConstrutionUpUpCenter2;
    @Bind(R.id.rl_constrution_up_center2)
    RelativeLayout rlConstrutionUpCenter2;
    @Bind(R.id.rl_constrution_down_contain)
    RelativeLayout rl_constrution_down_contain;
    @Bind(R.id.iv_constrution_left)
    ImageView ivConstrutionLeft;
    @Bind(R.id.iv_constrution_right)
    ImageView ivConstrutionRight;
    @Bind(R.id.iv_constrution_back)
    ImageView iv_constrution_back;
    @Bind(R.id.iv_constrution_center1)
    ImageView ivConstrutionCenter1;
    @Bind(R.id.iv_constrution_center2)
    ImageView ivConstrutionCenter2;
    @Bind(R.id.iv_good_hand)
    ImageView ivGoodHand;
    @Bind(R.id.iv_good_star)
    ImageView ivGoodStar;
    @Bind(R.id.rl_good)
    RelativeLayout rlGood;
    private Activity mContext = null;
    private View mView = null;
    private Cursor cursor;



    private ViewGroup anim_mask_layout;//动画层
    private int lessonType = 13;
    private int weithLess = 0;
    private int currentPosition = 0;
    private int currentPositionZ = 0;
    private List<AppDataBean> mDataList;
    private List<String> total = new ArrayList<>();
    private List<Integer> picLists;

    Set setDown = new HashSet();
    private LessonProgressInterface mListener = null;
    private NextLessonInterface mNextListener = null;
    private String mMp3SourceDir = null;
    private boolean isFirst = true;
    private int bg1Id, bg2id;
    private AlphaAnimation alphaAnimation1;
    private TranslateAnimation alphaAnimation2;
    private int totalNumber=2;
    private List<Type15Bean> mIsDoing;
    private List<Integer> weitotal  =new ArrayList<>();
    public StudyConsructionView(Context context) {
        super(context);
        initViews(context);
    }

    public StudyConsructionView(Context context, AttributeSet attrs) {
        super(context, attrs);
        initViews(context);
    }

    private void initViews(Context context) {
        mContext = (Activity) context;
        mView = LayoutInflater.from(context).inflate(R.layout.study_constrution_view, null);
        ButterKnife.bind(this, mView);
        this.addView(mView);
      /*  cursorZ = DBHelper.getInstance(mContext).query(DBHelper.RES_TABLE, " type=? ", new String[]{lessonType + ""});
        cursorZ.getCount();*/
        weitotal.clear();
        for (int i = 0; i <16 ; i++) {
          Cursor  cursor=DBHelper.getInstance(mContext).query(DBHelper.RES_TABLE, " type=?  and weight=?", new String[]{lessonType + "", i + ""});
            weitotal.add(cursor.getCount());
        }


    }
    private void setFirstAnimation() {
        ivXiaoshouConstrution.setVisibility(VISIBLE);
        //闪烁
        alphaAnimation1 = new AlphaAnimation(0.1f, 1.0f);
        alphaAnimation1.reset();
        alphaAnimation1.setDuration(1000);
        alphaAnimation1.setRepeatCount(2);
//        alphaAnimation1.setRepeatMode(Animation.);
        ivXiaoshouConstrution.setAnimation(alphaAnimation1);
        alphaAnimation1.start();
        //摇摆
       /* TranslateAnimation  alphaAnimation2 = new TranslateAnimation(150f, 180f, 50, 80);
        alphaAnimation2.setDuration(1000);
        alphaAnimation2.setRepeatCount(Animation.INFINITE);
        ivHandClick.setAnimation(alphaAnimation2);
        alphaAnimation2.start();*/
    }


    private void setRightAnimation() {
        rlGood.setVisibility(VISIBLE);
        Animation animation1 = AnimationUtils.loadAnimation(mContext, R.anim.translate_good_star_in);
        ivGoodStar.setAnimation(animation1);
        scaleIn(ivGoodHand, 300, 500, new Animation.AnimationListener() {
            @Override
            public void onAnimationStart(Animation animation) {

            }

            @Override
            public void onAnimationEnd(Animation animation) {
                rlGood.postDelayed(new Runnable() {
                    @Override
                    public void run() {

                    }
                }, 1000);
            }

            @Override
            public void onAnimationRepeat(Animation animation) {

            }
        });
    }

    public void initData() {

        mDataList = new ArrayList<AppDataBean>();
        mIsDoing = new ArrayList<>();
        mDataList.clear();
        mIsDoing.clear();
        picLists = new ArrayList<>();


       // cursor = DBHelper.getInstance(mContext).query(DBHelper.RES_TABLE, " type=?  and weight=?", new String[]{lessonType + "", weithLess + ""});
        cursor = DBHelper.getInstance(mContext).query(DBHelper.RES_TABLE, " type=?  ", new String[]{lessonType + ""});

        if (cursor != null)
            Logger.e("xionghy-cursor: " + cursor.getCount());
        while (cursor.moveToNext()) {
            AppDataBean d = new AppDataBean();
            Type15Bean type15Bean = new Type15Bean();
            type15Bean.setDoing(false);
            d.setChinese(cursor.getString(cursor.getColumnIndex("chinese")));
            d.setPinyin(cursor.getString(cursor.getColumnIndex("pinyin")));
            d.setPhone(cursor.getString(cursor.getColumnIndex("phone")));
            d.setTone(cursor.getString(cursor.getColumnIndex("tone")));
            d.setAudioName(cursor.getString(cursor.getColumnIndex("audioName")));
            d.setPicName(cursor.getString(cursor.getColumnIndex("picName")));
            d.setType(cursor.getInt(cursor.getColumnIndex("type")));
            d.setGroupID(cursor.getInt(cursor.getColumnIndex("groupId")));
            d.setWeight(cursor.getInt(cursor.getColumnIndex("weight")));
            mIsDoing.add(type15Bean);
            mDataList.add(d);
        }

        if (mDataList.size() <= 0) {
            Logger.e("获取到的数据为空。。。。");
            return;
        }
        updateViewData();
    }

    public void setLessonType(int type) {
        lessonType = type;
        if (lessonType == 0) {

        } else if (lessonType == 2) {

        }
    }

    public void setWeithLesson(int weithLesson,int number) {

        this.weithLess = weithLesson;
        if (weithLesson == 0) {
            iv_constrution_back.setImageResource(R.mipmap.list_zy);
            if(0==number){
                this.currentPosition=currentPosition;
            }

        } else if (weithLesson == 1) {
            iv_constrution_back.setImageResource(R.mipmap.list_zzy);
            if(0==number){

                currentPosition=weitotal.get(0);
            }


        } else if (weithLesson == 2) {
            if(0==number){

                currentPosition=weitotal.get(0)+weitotal.get(1);
            }
            iv_constrution_back.setImageResource(R.mipmap.list_sx);


        } else if (weithLesson == 3) {
            iv_constrution_back.setImageResource(R.mipmap.list_szx);

            if(0==number){

                currentPosition=weitotal.get(0)+weitotal.get(1)+weitotal.get(2);
            }
        } else if (weithLesson == 4) {

            iv_constrution_back.setImageResource(R.mipmap.list_zsx);
            if(0==number){

                currentPosition=weitotal.get(0)+weitotal.get(1)+weitotal.get(2)+weitotal.get(3);
            }
        } else if (weithLesson == 5) {
            currentPosition=weitotal.get(0)+weitotal.get(1)+weitotal.get(2)+weitotal.get(3)+weitotal.get(4);
            iv_constrution_back.setImageResource(R.mipmap.list_sxy);
        } else if (weithLesson == 6) {
            if(0==number){
                currentPosition=weitotal.get(0)+weitotal.get(1)+weitotal.get(2)+weitotal.get(3)+weitotal.get(4)
                        +weitotal.get(5)
                ;
            }

            iv_constrution_back.setImageResource(R.mipmap.list_sxzy);
        } else if (weithLesson == 7) {
            if(0==number){
                currentPosition=weitotal.get(0)+weitotal.get(1)+weitotal.get(2)+weitotal.get(3)+weitotal.get(4)
                        +weitotal.get(5)+weitotal.get(6)
                ;
            }

            iv_constrution_back.setImageResource(R.mipmap.list_szy);
        } else if (weithLesson == 8) {
            if(0==number){
                currentPosition=weitotal.get(0)+weitotal.get(1)+weitotal.get(2)+weitotal.get(3)+weitotal.get(4)
                        +weitotal.get(5)+weitotal.get(6)+weitotal.get(7)
                ;
            }

            iv_constrution_back.setImageResource(R.mipmap.list_zyx);
        } else if (weithLesson == 9) {
            if(0==number){
                currentPosition=weitotal.get(0)+weitotal.get(1)+weitotal.get(2)+weitotal.get(3)+weitotal.get(4)
                        +weitotal.get(5)+weitotal.get(6)+weitotal.get(7)+weitotal.get(8)
                ;
            }

            iv_constrution_back.setImageResource(R.mipmap.list_bw1);
        } else if (weithLesson == 10) {
            if(0==number){
                currentPosition=weitotal.get(0)+weitotal.get(1)+weitotal.get(2)+weitotal.get(3)+weitotal.get(4)
                        +weitotal.get(5)+weitotal.get(6)+weitotal.get(7)+weitotal.get(8)+weitotal.get(9)
                ;
            }

            iv_constrution_back.setImageResource(R.mipmap.list_bw2);
        } else if (weithLesson == 11) {
            if(0==number){
                currentPosition=weitotal.get(0)+weitotal.get(1)+weitotal.get(2)+weitotal.get(3)+weitotal.get(4)
                        +weitotal.get(5)+weitotal.get(6)+weitotal.get(7)+weitotal.get(8)+weitotal.get(9)+weitotal.get(10)
                ;
            }

            iv_constrution_back.setImageResource(R.mipmap.list_bw3);
        } else if (weithLesson == 12) {
            if(0==number){
                currentPosition=weitotal.get(0)+weitotal.get(1)+weitotal.get(2)+weitotal.get(3)+weitotal.get(4)
                        +weitotal.get(5)+weitotal.get(6)+weitotal.get(7)+weitotal.get(8)+weitotal.get(9)+weitotal.get(10)
                        +weitotal.get(11)
                ;
            }

            iv_constrution_back.setImageResource(R.mipmap.list_bw4);
        } else if (weithLesson == 13) {
            if(0==number){
                currentPosition=weitotal.get(0)+weitotal.get(1)+weitotal.get(2)+weitotal.get(3)+weitotal.get(4)
                        +weitotal.get(5)+weitotal.get(6)+weitotal.get(7)+weitotal.get(8)+weitotal.get(9)+weitotal.get(10)
                        +weitotal.get(11)+weitotal.get(12)
                ;
            }

            iv_constrution_back.setImageResource(R.mipmap.list_bw5);
        } else if (weithLesson == 14) {
            if(0==number){
                currentPosition=weitotal.get(0)+weitotal.get(1)+weitotal.get(2)+weitotal.get(3)+weitotal.get(4)
                        +weitotal.get(5)+weitotal.get(6)+weitotal.get(7)+weitotal.get(8)+weitotal.get(9)+weitotal.get(10)
                        +weitotal.get(11)+weitotal.get(12)+weitotal.get(13)
                ;
            }
            currentPosition=weitotal.get(0)+weitotal.get(1)+weitotal.get(2)+weitotal.get(3)+weitotal.get(4)
                    +weitotal.get(5)+weitotal.get(6)+weitotal.get(7)+weitotal.get(8)+weitotal.get(9)+weitotal.get(10)
                    +weitotal.get(11)+weitotal.get(12)+weitotal.get(13)
            ;
            iv_constrution_back.setImageResource(R.mipmap.list_bw6);
        } else if (weithLesson == 15) {
            if(0==number){
                currentPosition=weitotal.get(0)+weitotal.get(1)+weitotal.get(2)+weitotal.get(3)+weitotal.get(4)
                        +weitotal.get(5)+weitotal.get(6)+weitotal.get(7)+weitotal.get(8)+weitotal.get(9)+weitotal.get(10)
                        +weitotal.get(11)+weitotal.get(12)+weitotal.get(13)+weitotal.get(14)
                ;
            }

            iv_constrution_back.setImageResource(R.mipmap.list_bw7);
        }

    }


    public void nextWord() {
        // TODO 数据切换，涉及到界面上文字和图片的切换

        currentPosition++;
        if (currentPosition < mDataList.size()) {
            updateViewData();

        } else {

            Utils.showDialog(mContext, R.string.next_lesson_dialog_msg, lessonType, mNextListener);


        }
    }


    private void startTask(float t, final AnimationDrawable draw) {
        if (draw == null) return;
        Timer timer = new Timer();
        timer.schedule(new TimerTask() {
            @Override
            public void run() {
                draw.stop();
            }
        }, (int) (t * 1000));
    }

    public void beforeWord() {
        if (currentPosition <= 0 )
            return;

            currentPosition--;
            if (currentPosition < mDataList.size()) {
                updateViewData();

            } else {
                // TODO 进入下一课. 会掉到StudyActivity页面来进行View的切换
                // mNextListener.onLessonChanged(lessonType - 1);
                /*weithLess--;
                currentPosition = 0;
                initData();
                setWeithLesson(weithLess);*/
            }


    }

    public void setListener(LessonProgressInterface listener) {
        mListener = listener;
    }

    public void setNextListener(NextLessonInterface listener) {
        mNextListener = listener;
    }

    private List<Integer> getPicName(String str) {
        picLists.clear();
        if (!str.equals("") || str.equals("null")) {
            String tones[] = str.replace("|", " ").split(" ");
            for (int i = 0; i < tones.length; i++) {
                picLists.add(getResource(tones[i]));
            }

        }
        return picLists;
    }

    public int getResource(String imageName) {
        Context ctx = mContext.getBaseContext();
        int resId = getResources().getIdentifier(imageName, "drawable", ctx.getPackageName());
        return resId;
    }

    private void updateViewData() {
        if (currentPosition < 0) return;


        AppDataBean data = mDataList.get(currentPosition);
        if (mListener != null) {
            mListener.setProgress(mDataList.size(), currentPosition);
        }
        tvHao.setText(data.getChinese());


        String[] splitpic = data.getAudioName().replace("|", " ").split(" ");
        String[] split = data.getPicName().replace("|", " ").split(" ");
        if (split.length == 2) {
            ivConstrutionLeft.setImageResource(getResource(splitpic[0]));
            ivConstrutionRight.setImageResource(getResource(splitpic[1]));
            tvConstrutionUpLeft.setText(split[0]);
            tvConstrutionUpUpCenter1.setText(split[1]);
            totalNumber=2;
        } else if (split.length == 3) {
            ivConstrutionLeft.setImageResource(getResource(splitpic[0]));
            ivConstrutionRight.setImageResource(getResource(splitpic[1]));
            ivConstrutionCenter1.setImageResource(getResource(splitpic[2]));
            tvConstrutionUpLeft.setText(split[0]);
            tvConstrutionUpUpCenter1.setText(split[1]);
            tvConstrutionUpUpCenter2.setText(split[2]);
            totalNumber=3;

        } else if (split.length == 4) {
            ivConstrutionLeft.setImageResource(getResource(splitpic[0]));
            ivConstrutionRight.setImageResource(getResource(splitpic[1]));
            ivConstrutionCenter1.setImageResource(getResource(splitpic[2]));
            ivConstrutionCenter2.setImageResource(getResource(splitpic[3]));
            tvConstrutionUpLeft.setText(split[0]);
            tvConstrutionUpUpCenter1.setText(split[1]);
            tvConstrutionUpUpCenter2.setText(split[2]);
            tvConstrutionUpRight.setText(split[3]);
            totalNumber=4;
        }

        rlGood.setVisibility(GONE);
        if(weithLess==0 && currentPosition==0){
            setFirstAnimation();
        }else {
            ivXiaoshouConstrution.setVisibility(GONE);
        }
        setWeithLesson(data.getWeight(),1);
        setDown.clear();
        addAnimation();
        resetView();
        resetFirstToneImg(split.length);
    }



    private void checkResult(TextView view, boolean isTrue, int tone) {

        if (isTrue) {
            HsSoundUtil.play(mContext, R.raw.right);
            // TODO 设置当前选择正确的标识
            if (tone == 1) {
                view.setTextColor(mContext.getResources().getColor(R.color.construction_textright));
                rlConstrutionUpLeft.setVisibility(INVISIBLE);
                ivConstrutionLeft.setVisibility(VISIBLE);

            } else if (tone == 2) {
                view.setTextColor(mContext.getResources().getColor(R.color.construction_textright));
                rlConstrutionUpCenter1.setVisibility(INVISIBLE);
                ivConstrutionRight.setVisibility(VISIBLE);
                if(totalNumber==2){
                    setRightAnimation();
                }
            } else if (tone == 3) {
                view.setTextColor(mContext.getResources().getColor(R.color.construction_textright));
                rlConstrutionUpCenter2.setVisibility(INVISIBLE);
                ivConstrutionCenter1.setVisibility(VISIBLE);
                if(totalNumber==3){
                    setRightAnimation();
                }
            } else if (tone == 4) {
                view.setTextColor(mContext.getResources().getColor(R.color.construction_textright));
                rlConstrutionUpRight.setVisibility(INVISIBLE);
                ivConstrutionCenter2.setVisibility(VISIBLE);
                if(totalNumber==4){
                    setRightAnimation();
                }
            }

            AnimatorUtil.pluseAnimator(mContext, view);
        } else {
            // TODO 设置成错误的颜色
            HsSoundUtil.play(mContext, R.raw.wrong);

            resetView();

            if (tone == 1) {
                view.setTextColor(mContext.getResources().getColor(R.color.construction_textwrong));
                rlConstrutionUpLeft.setBackgroundResource(R.drawable.shape_hanziwrite);
            } else if (tone == 2) {
                view.setTextColor(mContext.getResources().getColor(R.color.construction_textwrong));
                rlConstrutionUpCenter1.setBackgroundResource(R.drawable.shape_hanziwrite);
            } else if (tone == 3) {
                view.setTextColor(mContext.getResources().getColor(R.color.construction_textwrong));
                rlConstrutionUpCenter2.setBackgroundResource(R.drawable.shape_hanziwrite);

            } else if (tone == 4) {
                view.setTextColor(mContext.getResources().getColor(R.color.construction_textwrong));
                rlConstrutionUpRight.setBackgroundResource(R.drawable.shape_hanziwrite);
            }

            AnimatorUtil.shakeAnimator(mContext, view);



        }
    }

    private void resetView() {

        rlConstrutionUpLeft.setBackgroundResource(R.mipmap.cicletranspant);
        rlConstrutionUpCenter1.setBackgroundResource(R.mipmap.cicletranspant);
        rlConstrutionUpCenter2.setBackgroundResource(R.mipmap.cicletranspant);
        rlConstrutionUpRight.setBackgroundResource(R.mipmap.cicletranspant);
        tvConstrutionUpRight.setTextColor(mContext.getResources().getColor(R.color.construction_textnormal));
        tvConstrutionUpLeft.setTextColor(mContext.getResources().getColor(R.color.construction_textnormal));
        tvConstrutionUpUpCenter1.setTextColor(mContext.getResources().getColor(R.color.construction_textnormal));
        tvConstrutionUpUpCenter2.setTextColor(mContext.getResources().getColor(R.color.construction_textnormal));

    }

    public void onDestroy() {


        if (cursor != null)
            cursor.close();
    }
    boolean isTrue = false;
    private static final int MESSAGE_LOGIN = 1;
    Handler handler = new Handler(new Handler.Callback(){
        @Override
        public boolean handleMessage(Message msg) {
            if(msg.what == MESSAGE_LOGIN ){
                //登录逻辑

                checkResult(tvConstrutionUpUpCenter1, true, 2);
            }

            return true;
        }
    });
    @OnClick({R.id.rl_constrution_up_left, R.id.rl_constrution_up_right, R.id.iv_xiaoshou_constrution, iv_constrution_left, R.id.iv_constrution_right, R.id.rl_constrution_up_center1, R.id.rl_constrution_up_center2})
    public void onViewClicked(View view) {

        switch (view.getId()) {
            case R.id.rl_constrution_up_left:
                if (currentPosition == 0 && weithLess==0) {

                    //  setFirstAnimation();
                }else {
                    if (setDown.size() == 0) {
                        setDown.add("1");
                        isTrue = true;
                    } else {
                        isTrue = false;
                    }
                    checkResult(tvConstrutionUpLeft, isTrue, 1);
                }

                break;
            case R.id.rl_constrution_up_right:
                saveData(4);
                if (setDown.size() == 3) {
                    setDown.add("4");
                    isTrue = true;
                } else {
                    isTrue = false;
                }
                checkResult(tvConstrutionUpRight, isTrue, 4);

                break;
            case R.id.iv_xiaoshou_constrution:
                checkResult(tvConstrutionUpLeft, true, 1);
                ivXiaoshouConstrution.setVisibility(GONE);
                handler.sendEmptyMessageDelayed(MESSAGE_LOGIN,1000);
                break;
            case R.id.rl_constrution_up_center1:
                saveData(2);
                if (currentPosition == 0 && weithLess==0) {

                    //  setFirstAnimation();
                }else {
                    if (setDown.size() == 1) {
                        setDown.add("2");
                        isTrue = true;
                    } else {
                        isTrue = false;
                    }
                    checkResult(tvConstrutionUpUpCenter1, isTrue, 2);
                }


                break;
            case R.id.rl_constrution_up_center2:
                saveData(3);
                if (setDown.size() == 2) {
                    setDown.add("3");
                    isTrue = true;
                } else {
                    isTrue = false;
                }
                checkResult(tvConstrutionUpUpCenter2, isTrue, 3);
                break;
        }
    }

    private void saveData(int i) {
        if(i==totalNumber){
            Type15Bean type15Bean = mIsDoing.get(currentPosition);
            type15Bean.setDoing(true);
        }
    }

    private void resetFirstToneImg(int number) {
        Type15Bean type15Bean = mIsDoing.get(currentPosition);
        if (number == 2) {
            if(type15Bean.isDoing()){
                rlConstrutionUpLeft.setVisibility(INVISIBLE);
                rlConstrutionUpCenter1.setVisibility(INVISIBLE);
                ivConstrutionLeft.setVisibility(VISIBLE);
                ivConstrutionRight.setVisibility(VISIBLE);
            }else {
                rlConstrutionUpLeft.setVisibility(VISIBLE);
                rlConstrutionUpCenter1.setVisibility(VISIBLE);
                ivConstrutionLeft.setVisibility(INVISIBLE);
                ivConstrutionRight.setVisibility(INVISIBLE);
            }

            rlConstrutionUpCenter2.setVisibility(GONE);
            rlConstrutionUpRight.setVisibility(GONE);
            ivConstrutionCenter1.setVisibility(INVISIBLE);
            ivConstrutionCenter2.setVisibility(INVISIBLE);
        } else if (number == 3) {
            if(type15Bean.isDoing()){
                rlConstrutionUpLeft.setVisibility(INVISIBLE);
                rlConstrutionUpCenter1.setVisibility(INVISIBLE);
                rlConstrutionUpCenter2.setVisibility(INVISIBLE);
                ivConstrutionLeft.setVisibility(VISIBLE);
                ivConstrutionRight.setVisibility(VISIBLE);
                ivConstrutionCenter1.setVisibility(VISIBLE);
            }else {
                rlConstrutionUpLeft.setVisibility(VISIBLE);
                rlConstrutionUpCenter1.setVisibility(VISIBLE);
                rlConstrutionUpCenter2.setVisibility(VISIBLE);
                ivConstrutionLeft.setVisibility(INVISIBLE);
                ivConstrutionRight.setVisibility(INVISIBLE);
                ivConstrutionCenter1.setVisibility(INVISIBLE);
            }

            rlConstrutionUpRight.setVisibility(GONE);
            ivConstrutionCenter2.setVisibility(INVISIBLE);
        } else if (number == 4) {
            if(type15Bean.isDoing()){
                rlConstrutionUpLeft.setVisibility(INVISIBLE);
                rlConstrutionUpCenter1.setVisibility(INVISIBLE);
                rlConstrutionUpCenter2.setVisibility(INVISIBLE);
                rlConstrutionUpRight.setVisibility(INVISIBLE);
                ivConstrutionLeft.setVisibility(VISIBLE);
                ivConstrutionRight.setVisibility(VISIBLE);
                ivConstrutionCenter1.setVisibility(VISIBLE);
                ivConstrutionCenter2.setVisibility(VISIBLE);
            }else {
                rlConstrutionUpLeft.setVisibility(VISIBLE);
                rlConstrutionUpCenter1.setVisibility(VISIBLE);
                rlConstrutionUpCenter2.setVisibility(VISIBLE);
                rlConstrutionUpRight.setVisibility(VISIBLE);
                ivConstrutionLeft.setVisibility(INVISIBLE);
                ivConstrutionRight.setVisibility(INVISIBLE);
                ivConstrutionCenter1.setVisibility(INVISIBLE);
                ivConstrutionCenter2.setVisibility(INVISIBLE);
            }


        }


    }

    // 每个空间都添加一种动画
    long durationMillis = 1000, delayMillis = 0;
    private Animation chooseViewAnimation = null;
    private Animation.AnimationListener wordViewAnimListener = null;

    private void addAnimation() {
        if (rl_contstrction_parient != null) {
            wordViewAnimListener = new Animation.AnimationListener() {
                @Override
                public void onAnimationStart(Animation animation) {
                }

                @Override
                public void onAnimationEnd(Animation animation) {


                }

                @Override
                public void onAnimationRepeat(Animation animation) {
                }
            };
            chooseViewAnimation = scaleIn(rl_contstrction_parient, durationMillis, delayMillis, wordViewAnimListener);
            rl_contstrction_parient.post(new Runnable() {
                @Override
                public void run() {
                    chooseViewAnimation.start();

                }
            });

        }
    }

    private Animation scaleIn(View view, long durationMillis, long delayMillis, Animation.AnimationListener l) {
        ScaleAnimation animation = new ScaleAnimation(0, 1, 0, 1, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
        animation.setDuration(durationMillis);
        animation.setStartOffset(delayMillis);
        view.setVisibility(View.VISIBLE);
        view.startAnimation(animation);
        animation.setAnimationListener(l);
        animation.cancel();
        return animation;
    }

}
